# 使用modelform，进行表单的快速生成并使用bootstrap样式
# 1、引入django forms
from django import forms


# BootStrap父类#，重写init方法，找到widget插件，循环批量操作attrs内容，子类继承
class BootStrap:
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        for name, field in self.fields.items():
            # 通过判断去单独调整
            # if name == "password":
            #     continue
            if field.widget.attrs:
                field.widget.attrs['class'] = "form-control"
                field.widget.attrs['placeholder'] = field.label
            else:
                field.widget.attrs = {
                    "class": "form-control",
                    "placeholder": field.label
                }


class BootStrapModelForm(BootStrap, forms.ModelForm):
    pass


class BootStrapForm(BootStrap, forms.Form):
    pass
